package cn.maihe.elg.operation.model.enums;

import java.util.Arrays;

/**
 * @Description 保函品种
 * @Author WJH
 * @Date 2021/03/25
 */
public enum GuaranteeCategory {

    BID(0, "投标保函"),
    PERFORMANCE(1, "履约保函"),
    ADVANCE_PAYMENT(2, "预付款保函"),
    MIGRANT_SALARY(3, "农民工工资保函"),
    QUALITY(4, "质量保修保函");

    private int category;
    private String desc;

    GuaranteeCategory(int category, String desc) {
        this.category = category;
        this.desc = desc;
    }

    public int getCategory() {
        return category;
    }

    public String getCategoryStr() {
        return String.valueOf(category);
    }

    public String getDesc() {
        return desc;
    }

    public static GuaranteeCategory resolve(int category) {
        return Arrays.stream(values()).filter(o -> o.getCategory() == category).findFirst().orElseThrow(() -> new RuntimeException("保函品种非法[" + category + "]"));
    }


    public static GuaranteeCategory resolve(String categoryStr) {
        try {
            return resolve(Integer.valueOf(categoryStr));
        } catch (NumberFormatException e) {
            throw new RuntimeException("保函品种非法[" + categoryStr + "]", e);
        }
    }

    public static String getDescByType(String category) {
        try {
            GuaranteeCategory guaranteeCategory = resolve(category);
            return guaranteeCategory.getDesc();
        } catch (Exception e) {
        }
        return "";
    }
}
